package com.lh.createData.service.Impl;

import com.lh.createData.dao.ActionMapper;
import com.lh.createData.dto.ActionDto;
import com.lh.createData.model.ActionModel;
import com.lh.createData.model.ActionProductModel;
import com.lh.createData.model.ActionUserCountModel;
import com.lh.createData.model.ActionUserIniModel;
import com.lh.createData.model.InPutParam.*;
import com.lh.createData.service.ActionService;
import com.lh.createData.unit.SeparateTableClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author ：梁昊，后端工程师：梁昊
 * @create 2021-07-20 12:51
 * @function
 * @editLog
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class ActionServiceImpl implements ActionService {
    @Autowired
    ActionMapper actionMapper;
    @Autowired
    SeparateTableClass separateTableClass;

    @Override
    public <T> String getSeparateTableNo(T id, Class<T> tClass) {
        Object object;
        if (tClass.getName() == "int")
            object = separateTableClass.getSeparateTableNo(id.toString());
        else
            object = separateTableClass.getSeparateTableNo(id.toString());
        return (String) object;
    }

    /**
     * 根据项目ID，得到功能菜单点击次数统计
     *
     * @param actionInParam com.lh.createData.model.InPutParam.ActionInParam
     * @return 项目基础信息
     */
    @Override
    public List<ActionModel> selectActionTotalForInNum(ActionInParam actionInParam) {
        actionInParam.setTableNo(this.getSeparateTableNo(actionInParam.getSeparateId(), String.class));
        return actionMapper.selectActionTotalForInNum(actionInParam);
    }
    /**
     * 生成项目节点树
     *
     * @param actionInParam 分表标识ID
     * @return 项目基础信息
     */
    @Override
    public List<ActionDto> createProjectNode(ActionInParam actionInParam) {
        actionInParam.setTableNo(this.getSeparateTableNo(actionInParam.getSeparateId(), String.class));
        return actionMapper.createProjectNode(actionInParam);
    }

    @Override
    public List<ActionModel> createProductTree(ActionInParam actionInParam) {
        actionInParam.setTableNo(this.getSeparateTableNo(actionInParam.getSeparateId(), String.class));
        return actionMapper.createProductTree(actionInParam);
    }

    @Override
    public List<ActionModel> getMenuListGroupBy(ActionInParam actionInParam) {
        actionInParam.setTableNo(this.getSeparateTableNo(actionInParam.getSeparateId(), String.class));
        return actionMapper.getMenuListGroupBy(actionInParam);
    }

    @Override
    public List<ActionModel> getProjectListGroupBy(ActionInParam actionInParam) {
        actionInParam.setTableNo(this.getSeparateTableNo(actionInParam.getSeparateId(), String.class));
        return actionMapper.getProjectListGroupBy(actionInParam);
    }

    /**
     * 展示端方法：为用户时长与界面跳转提供原始数据
     *
     * @param actionUserIniInParam com.lh.createData.model.InPutParam.ActionUserIniInParam
     * @return 月统计
     */
    @Override
    public List<ActionUserIniModel> selectActionForUserTimeAndJump(ActionUserIniInParam actionUserIniInParam) {
        actionUserIniInParam.setTableNo(this.getSeparateTableNo(actionUserIniInParam.getSeparateId(), String.class));

        final List<ActionUserIniModel> actionUserIniModels = actionMapper.selectActionForUserTimeAndJump(actionUserIniInParam);

        return actionUserIniModels;
    }

    @Override
    public int updateActionTotalForInNum(ActionInParam actionInParam) {
        return actionMapper.updateActionTotalForInNum(actionInParam);
    }

    /**
     * 展示端方法：更新统计次数
     *
     * @param actionUpdateCountInParam com.lh.createData.model.InPutParam.ActionUpdateCountInParam
     * @return 影响条数
     */
    @Override
    public int updateActionCounter (ActionUpdateCountInParam actionUpdateCountInParam) {
        actionUpdateCountInParam.setTableNo(this.getSeparateTableNo(actionUpdateCountInParam.getSeparateId(), String.class));
        return actionMapper.updateActionCounter(actionUpdateCountInParam);
    }

    /**
     * 展示端方法：用户数、同比
     *
     * @param actionUserCountInParam com.lh.createData.model.InPutParam.ActionUserCountInParam
     * @return 得到项目信息与标定、分值信息
     */
    @Override
    public List<ActionUserCountModel> createUserCount(ActionUserCountInParam actionUserCountInParam) {
        actionUserCountInParam.setTableNo(this.getSeparateTableNo(actionUserCountInParam.getSeparateId(), String.class));
        return actionMapper.createUserCount(actionUserCountInParam);
    }

    /**
     * 得到产品信息，并保存
     *
     * @param separateId 分表标识ID
     * @return 每月统计一次
     */
    @Override
    public List<ActionProductModel> selectProductGroupBy(String separateId) {
        return actionMapper.selectProductGroupBy(separateId);
    }

    @Override
    public int clearHistoryData(DeleteDataInParam deleteDataInParam) {
        return actionMapper.clearHistoryData(deleteDataInParam);
    }

}